package sonic.game.tile;
import java.awt.Graphics;

import sonic.game.Game;
import sonic.game.animation.Animation;
import sonic.game.character.Sonic;
import sonic.game.util.Vector2D;

/**
 * Game Projectile
 * 
 * Base class for all projectiles fired by characters (or the environment)
 * 
 * @author RGreenlees
 *
 */

public class GameProjectile extends DynamicTile {
	
	private Animation anim;
	
	/** Constructor sets the start position, initial direction and speed, as well as appearance */
	public GameProjectile(Vector2D startPos, Vector2D startVelocity, float startSpeed, Animation flyAnim)
	{
		super(startPos);
		anim = flyAnim;
		velocity.x = startVelocity.x * startSpeed;
		velocity.y = startVelocity.y * startSpeed;
		physicsType = ePhysicsType.PHYS_FLYING;
		collisionType = eCollisionType.CT_TOUCHALL;
		Game.currentMap.pendingTiles.add(this);
	}
	
	public void paint(Graphics g)
	{
		if (anim != null && anim.getCurrentFrame() != null)
		{
			g.drawImage(anim.getCurrentFrame(false), (int) location.x + (320-(int) Game.camera.location.x), (int) location.y + (240-(int) Game.camera.location.y), null);
		}
	}
	
	public void hitWall(Tile a)
	{
		destroy();
	}
	
	public void landedOnBy(Tile a)
	{
		destroy();
	}
	
	public void landedOn(Tile a)
	{
		destroy();
	}
	
	public void touch(Tile toucher)
	{
		// Only destroy if it touches Sonic, otherwise it will pass right through
		if (toucher instanceof Sonic)
		{
			destroy();
		}
	}
	
}
